package com.xianggu.tomcat;

import javax.servlet.ServletInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class BufferedServletInputStream extends ServletInputStream {
    private final ByteArrayInputStream buffer;

    public BufferedServletInputStream(byte[] data) {
        this.buffer = new ByteArrayInputStream(data);
    }

    @Override
    public int read() throws IOException {
        return buffer.read();
    }

    @Override
    public boolean isFinished() {
        return buffer.available() == 0;
    }

    @Override
    public boolean isReady() {
        return buffer.available() > 0;
    }

    @Override
    public void setReadListener(javax.servlet.ReadListener readListener) {
        throw new UnsupportedOperationException("Not supported");
    }
}